#pragma once

#include <stdint.h>

class gdbIORemote
{
public:
    virtual int open(const char *dev, long param = 0) = 0;
    virtual void close() = 0;
    virtual int read(void *buf, uint32_t max, int timeout_ms) = 0;
    virtual int write(const void *buf, uint32_t max, int timeout_ms) = 0;
    virtual bool nextReadReady() = 0;

public:
    int readAll(char *buf, uint32_t max, int timeout_ms)
    {
        int ret = 0;
        int len;

        while (ret != max)
        {
            len = read(buf, max - ret, timeout_ms);
            if (len <= 0)
            {
                if (ret == 0)
                    ret = len;

                break;
            }

            ret += len;
            buf += len;
        }

        return ret;
    }
};
